package com.iraeta.controller.basic;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.iraeta.controller.BaseController;
import com.iraeta.entity.main.Renyuanmapping;
import com.iraeta.service.basic.RenYuanMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController(value = "RenYuanMappingController")
@RequestMapping("renyuanmapping")
public class RenYuanMappingController extends BaseController {
    @Autowired
    RenYuanMappingService renYuanMappingService;

    @RequestMapping("page")
    public String page(@RequestBody JSONObject jo){
        String name = jo.getString("name");
        this.pageSet(jo);
        List<Renyuanmapping> renyuanmappingList = renYuanMappingService.selectByName(name);
        PageInfo<Renyuanmapping> rolePageInfo = this.getPageInfo(renyuanmappingList);
        return this.success(rolePageInfo);
    }

    @RequestMapping("get")
    public String get(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        Renyuanmapping Renyuanmapping = renYuanMappingService.get(id);
        return this.success(Renyuanmapping);
    }

    @RequestMapping("addedit")
    public String addEdit(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        Renyuanmapping Renyuanmapping = id == 0 ? new Renyuanmapping() :  renYuanMappingService.get(id);
        this.mapJsonToObj(paramJb, Renyuanmapping);
        if(id == 0){
            renYuanMappingService.add(Renyuanmapping);
        }else {
            renYuanMappingService.update(Renyuanmapping);
        }
        return this.success();
    }

    @RequestMapping("delete")
    public String delete(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        renYuanMappingService.delete(id);
        return this.success();
    }
}
